/*
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2021-01-29 14:58:29
 * @LastEditors: ding
 * @LastEditTime: 2022-08-05 10:48:29
 * @Description: file content
 */
"use strict";

import { EggAppConfig, PowerPartial } from "egg";
import * as path from "path";

export default () => {
	const config = {} as PowerPartial<EggAppConfig>;
	// config.myenv = appInfo.env;
	// appInfo.env = appInfo.env;

	// 内置安全插件配置
	config.security = {
		csrf: false, //可关闭csrf。临时postman测试时可以关闭，生产应该开启。
		domainWhiteList: ["*"],
	};
	// cors插件的配置。跨域插件。
	config.cors = {
		origin: "*",
		allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS",
	};

	// 修改内置的bodyParse配置，增加body的大小
	config.bodyParser = {
		jsonLimit: "100mb",
		formLimit: "100mb",
	};

	/* 日志配置 */
	config.logger = {
		dir: path.join(process.cwd(), "logs"),
		outputJSON: false, // 输出json日志，方便做日志监控
		consoleLevel: "WARN",
	};
	config.customLogger = {
		// appStartLogger:{
		//   file:path.join(process.cwd(),'logs','app-start.log')
		// }
	};

	// jwt校验插件 参数内置中间件可使用
	config.jwt = {
		secret: "fhsldghwoeihgtiowehrlgsdhfsljl24234hldkfsdfhls",
	};

	config.jwtLogin = {
		enable: true,
		expires: 2000,
		routeWhiteList: [],
	};

	config.catchNoCatchError = {
		enable: true,
	};

	// sequelize 插件的配置
	config.sequelize = {};

	config.customLoader = {
		// 自定义一个常量自动挂载目录
		consts: {
			inject: "app",
			loadunit: true,
			override: false,
			caseStyle: "lower",
			directory: "app/consts",
		},
		// 挂载一个目录封装数据处理功能，名曰：仓库，业务上应只以调用model或entity为主
		repos: {
			inject: "app",
			loadunit: false,
			override: false,
			caseStyle: "lower",
			directory: "app/repos",
			call: true,
		},
		// 挂载仓库,主要针对ctx，每次请求都会实例化
		repository: {
			inject: "ctx",
			loadunit: false,
			override: false,
			caseStyle: "lower",
			directory: "app/repository",
			call: true,
		},

		// 封装与ctx上下文无关的业务逻辑，纯业务逻辑，从service中可提取纯的业务逻辑，不涉及ctx访问。
		functions: {
			inject: "app",
			loadunit: true,
			override: false,
			caseStyle: "lower",
			directory: "app/functions",
			call: true,
		},
	};

	config.i18n = {
		// defaultLocale:"zh-CN"
	};

	return config;
};
